home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7902 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointer Cast
  5. Date: Tue, 13 Feb 1996 14:01:26 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <31208BA6.167EB0E7@intellektik.informatik.th-darmstadt.de>
  8. References: <1996Feb12.113703.5882@wisipc.weizmann.ac.il> <4foulo$d8v@adam.telalink.net>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. daver wrote:
  16. > In article <1996Feb12.113703.5882@wisipc.weizmann.ac.il>, cerlpvk says...
  17. > >
  18. > >First question.
  19. > >
  20. > >I read somewhere that before the notion of static member functions was
  21. > >introduced the way around was smth like that.
  22. > >
  23. > >(X*)0->func();
  24. > >Would someone kindly explain what this means.
  25. > >
  26. > ...
  27. > I have never seen the former used before but it is trying to call X::func
  28. > pretending that NULL points to a valid object.  This would generate a crash if
  29. > X::func attempts to dereference "this" (which static members are prevented from
  30. > doing), but it does allow X::func to be called without an instance of X.  I
  31. > would not recommend doing this!
  32.  
  33. I would say it was a sort of programming convention, to express that the appropriate
  34. function never access members. Such tricks are no longer necessary since 'static'
  35. member functions exists. In addition one should note that today in general the behavior 
  36. of calling a (non-static) member-function via a 'null' pointer is undefined no matter
  37. if the function accesses members or not.
  38.  
  39.     Enno
  40.